package com.qianfeng.easemob;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.easemob.EMCallBack;
import com.easemob.chat.EMChatManager;
import com.easemob.exceptions.EaseMobException;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
    @ViewById
    EditText username;
    @ViewById
    EditText psw;
    @ViewById(R.id.aginPsw)
    EditText aginPsw;
    @ViewById(R.id.register)
    Button register;

    @AfterViews
    public void init() {

    }

    @Click(R.id.register)
    public void onClick(View view) {
        register();
    }

    public void login() {
        final String name = username.getText().toString().trim();
        final String pswStr = psw.getText().toString().trim();
        EMChatManager.getInstance().login(name, pswStr, new EMCallBack() {
            @Override
            public void onSuccess() {

            }

            @Override
            public void onError(int i, String s) {

            }

            @Override
            public void onProgress(int i, String s) {

            }
        });
    }


    public void register() {
        final String name = username.getText().toString().trim();
        final String pswStr = psw.getText().toString().trim();
        String aginStr = aginPsw.getText().toString().trim();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    EMChatManager.getInstance().createAccountOnServer(name, pswStr);
                } catch (EaseMobException e) {
                    e.printStackTrace();
                }
            }
        }).start();


    }


}
